function write_xyz_file(co, filename)
%WRITE_XYZ_FILE Summary of this function goes here
%   Detailed explanation goes here
  fid = fopen([filename, '.xyz'], 'wt');  
  fprintf(fid, [num2str(sum(co.NumAtoms)), ' \n']);
  fprintf(fid, [filename, ' \n']);
  
  numAtomsTotal = zeros(size(co.NumAtoms, 1), 1);
  numAtomsTotal(1) = co.NumAtoms(1);
  for i = 2:size(co.NumAtoms, 1)
    numAtomsTotal(i) = numAtomsTotal(i-1)+co.NumAtoms(i);
  end
  
  j = 1;
  for i = 1:size(co.Positions, 1)
    if i <= numAtomsTotal(j)
      fprintf(fid, [co.AtomTypes{j}, '\t']);
    else
      j = j +1;
      fprintf(fid, [co.AtomTypes{j}, ' \t']);
    end      
    fprintf(fid, [num2str(co.Positions(i, :)), ' \n']);
  end
end

